package com.cloudservice.ccs.biz.impl;

import com.cloudservice.ccs.biz.ICommonWordBiz;
import com.cloudservice.ccs.entity.CommonWord;
import com.cloudservice.ccs.exception.BlackListException;
import com.cloudservice.ccs.exception.CommonWordException;
import com.cloudservice.ccs.mapper.CommonWordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CommonWordImpl implements ICommonWordBiz {
    @Autowired
    private CommonWordMapper commonWordMapper;
    @Override
    public void save(CommonWord commonWord) {
        int result = commonWordMapper.save(commonWord);
        if (result == 0) {
            throw new CommonWordException("Create CommonWord entity error");
        }
    }

    @Override
    public void update(Integer id, CommonWord commonWord) {
        int result = commonWordMapper.update(id, commonWord);
        if (result == 0) {
            throw new CommonWordException("Update CommonWord entity error");
        }
    }

    @Override
    public void delete(Integer id) {
        int result = commonWordMapper.delete(id);
        if (result == 0) {
            throw new CommonWordException("Delete CommonWord entity error");
        }
    }

    @Override
    public CommonWord getOne(Integer id) {
        CommonWord commonWord = commonWordMapper.getOne(id);
        if (commonWord == null) {
            throw new CommonWordException("Get CommonWord entity error: no such entity");
        }
        return commonWord;
    }

    @Override
    public List<CommonWord> getAll() {
        return commonWordMapper.getAll();
    }


    @Override
    public void partialUpdate(Integer id, Map<String, Object> fields) {
        int result = commonWordMapper.partialUpdate(id, fields);
        if (result == 0) {
            throw new CommonWordException("Update CommonWord entity error");
        }
    }
}
